<?php

require_once "tfsbox_shouts_view.class.php";

class TFsBOXControlPanelView extends TFsBOXAbstractView
	{
		function __construct(){}

		function renderControlPanel()
			{
				echo "<noscript>\n";
				echo "<div class=\"tfsbox_errors\">\n";
				echo "<b>Warning:</b> JavaScript is required in the Control Panel for certain, important features to work.\n";
				echo "</div>\n";
				echo "</noscript>\n";

				$this->renderMenuBar();

				echo "<div id=\"tfsbox_content\">\n";

				if (preg_match("#^/tfsbox/cpanel/filters/?#", $_SERVER['PATH_INFO']))
					$this->renderFiltersPage();

				else if (preg_match("#^/tfsbox/cpanel/users/?#", $_SERVER['PATH_INFO'])
					  && TFsBOX::$Database->databaseMode())
					$this->renderUsersPage();

				else if ($_SERVER['PATH_INFO'] == "/tfsbox/cpanel/subscriptions"
					  && TFsBOX::$Database->databaseMode())
					$this->renderSubscriptionsPage();

				else if (preg_match("#^/tfsbox/cpanel/mysql#", $_SERVER['PATH_INFO']))
				{
					if (filesize("mysql/db.php") == 0)
					{
						if ($_SERVER['PATH_INFO'] != "/tfsbox/cpanel/mysql/install"
						 || TFsBOX::$Session->hasErrors())
							$this->renderSetupDatabasePage();
					}

					else if ($_SERVER['PATH_INFO'] == "/tfsbox/cpanel/mysql/install"
						  && !TFsBOX::$Session->hasErrors())
						$this->renderSetupCompletePage();

					else
						TFsBOX::$Session->storeError("Information about the database appears to be present.");
				}

				else
					$this->renderShoutboxPage();

				echo "</div>\n";
			}

		protected function renderFiltersPage()
			{
				echo "<table class=\"tfsbox_container_plain\" cellspacing=\"5\" cellpadding=\"5\" border=\"0\" style=\"width: 100%;\">\n";
				echo "<tr>\n";
				echo "<td style=\"width: 50%;\">\n";

				// IP Management
				echo "<table class=\"tfsbox_container\" cellpadding=\"3\" border=\"0\" style=\"width: 100%;\">\n";
				echo "<tr>\n";
				echo "<th>IP Management</th>\n";
				echo "</tr>\n";
				echo "<tr>\n";
				echo "<td>\n";
				echo "<form name=\"tfsbox_cpanel_unban_ip\" action=\"". $_SERVER['SCRIPT_NAME'] ."/tfsbox/cpanel/filters/remove/ip\" method=\"post\">\n";
				echo "<select multiple=\"multiple\" name=\"tfsbox_unban_ips[]\" style=\"width: 100%;\">\n";
				foreach (TFsBOX::$Database->bannedIps() as $ip)
					echo "<option>". htmlentities($ip) ."</option>\n";
				echo "</select>\n";
				echo "</form>\n";
				echo "</td>\n";
				echo "</tr>\n";
				echo "<tr>\n";
				echo "<td style=\"text-align: right; background-color: #F0F0F0;\">\n";
				TFsBOXAbstractView::renderButton("Remove", "javascript: document.tfsbox_cpanel_unban_ip.submit();", TFsBOXSession::urlRoot() ."/images/icons/list-remove.png");
				echo "</td>\n";
				echo "</tr>\n";
				echo "</table>\n";
				//////////////////

				echo "</td>\n";
				echo "<td style=\"width: 50%;\">\n";

				// URL Filters
				echo "<table class=\"tfsbox_container\" cellpadding=\"3\" border=\"0\" style=\"width: 100%;\">\n";
				echo "<tr>\n";
				echo "<th>URL Filters</th>\n";
				echo "</tr>\n";
				echo "<tr>\n";
				echo "<td>\n";
				echo "<form name=\"tfsbox_cpanel_unban_url\" action=\"". $_SERVER['SCRIPT_NAME'] ."/tfsbox/cpanel/filters/remove/url\" method=\"post\">\n";
				echo "<select multiple=\"multiple\" name=\"tfsbox_unban_urls[]\" style=\"width: 100%;\">\n";
				foreach (TFsBOX::$Database->bannedUrls() as $url)
					echo "<option>". htmlentities($url) ."</option>\n";
				echo "</select>\n";
				echo "</form>\n";
				echo "</td>\n";
				echo "</tr>\n";
				echo "<tr>\n";
				echo "<td style=\"text-align: right; background-color: #F0F0F0;\">\n";
				TFsBOXAbstractView::renderButton("Remove", "javascript: document.tfsbox_cpanel_unban_url.submit();", TFsBOXSession::urlRoot() ."/images/icons/list-remove.png");
				echo "</td>\n";
				echo "</tr>\n";
				echo "</table>\n";
				//////////////////

				echo "</td>\n";
				echo "</tr>\n";
				echo "<tr>\n";
				echo "<td colspan=\"2\">\n";

				// Word filters
				echo "<table class=\"tfsbox_container\" cellpadding=\"3\" border=\"0\" style=\"width: 100%;\">\n";
				echo "<tr>\n";
				echo "<th colspan=\"3\">Word Filters</th>\n";
				echo "</tr>\n";
				echo "<tr>\n";
				echo "<td rowspan=\"3\" style=\"width: 50%;\">\n";
				echo "<form name=\"tfsbox_cpanel_remove_word_filter\" method=\"post\" action=\"". $_SERVER['SCRIPT_NAME'] ."/tfsbox/cpanel/filters/remove/word_filter\">\n";
				echo "<select name=\"tfsbox_remove_word_filter[]\" multiple=\"multiple\" style=\"width: 100%;\">\n";
				foreach (TFsBOX::$Database->wordFilters() as $filter)
					echo "<option>". htmlentities($filter->word) ."</option>\n";
				echo "</select>\n";
				echo "</form>\n";
				echo "</td>\n";
				echo "</tr>\n";
				echo "<tr>\n";
				echo "<form name=\"tfsbox_cpanel_add_word_filter\" method=\"post\" action=\"". $_SERVER['SCRIPT_NAME'] ."/tfsbox/cpanel/filters/add/word_filter\">\n";
				echo "<td style=\"background-color: #F0F0F0;\"><b>Word:</b></td>";
				echo "<td><input class=\"tfsbox_textfield\" type=\"text\" name=\"tfsbox_new_word_filter[]\"/></td>\n";
				echo "</tr>\n";
				echo "<tr>\n";
				echo "<td style=\"background-color: #F0F0F0;\"><b>Filter:</b></td>";
				echo "<td><input class=\"tfsbox_textfield\" type=\"text\" name=\"tfsbox_new_word_filter[]\"/></td>\n";
				echo "</form>\n";
				echo "</tr>\n";
				echo "<tr>\n";
				echo "<td style=\"text-align: right; background-color: #F0F0F0;\">\n";
				TFsBOXAbstractView::renderButton("Remove", "javascript: document.tfsbox_cpanel_remove_word_filter.submit();", TFsBOXSession::urlRoot() ."/images/icons/list-remove.png");
				echo "</td>\n";
				echo "<td colspan=\"2\" style=\"text-align: right; background-color: #F0F0F0;\">\n";
				TFsBOXAbstractView::renderButton("Add", "javascript: document.tfsbox_cpanel_add_word_filter.submit();", TFsBOXSession::urlRoot() ."/images/icons/list-add.png");
				echo "</td>\n";
				echo "</tr>\n";
				echo "</table>\n";
				//////////////////

				echo "</td>\n";
				echo "</tr>\n";
				echo "</table>\n";
			}

		function renderLoginForm()
			{
				echo "<form id=\"tfsbox_login_form\" action=\"". $_SERVER['REQUEST_URI'] ."\" method=\"post\">\n";
				echo "<table cellspacing=\"3\" cellpadding=\"3\" style=\"border: 0; width: 100%;\">\n";
				echo "<tr>\n";
				echo "<th colspan=\"2\">TFsBOX Control Panel</th>\n";
				echo "</tr>\n";
				echo "<tr>\n";
				echo "<td><b>Username:</b></td>\n";
				echo "<td><input class=\"tfsbox_textfield\" name=\"tfsbox_username\" type=\"text\" value=\"". $_POST['tfsbox_username'] ."\"/></td>\n";
				echo "</tr>\n";
				echo "<tr>\n";
				echo "<td><b>Password:</b></td>\n";
				echo "<td><input class=\"tfsbox_textfield\" name=\"tfsbox_password\" type=\"password\"/></td>\n";
				echo "</tr>\n";
				echo "<tr>\n";
				echo "<td></td>\n";
				echo "<td style=\"text-align: center;\">\n";
				echo "<input type=\"reset\" value=\"Clear\"/>\n";
				echo "<input type=\"submit\" value=\"Log In\"/>\n";
				echo "</td>\n";
				echo "</tr>\n";
				echo "</table>\n";
				echo "</form>\n";
			}

		protected function renderMenuBar()
			{
				$filters = (preg_match("#^/tfsbox/cpanel/filters/?#", $_SERVER['PATH_INFO'])) ? " id=\"active\"" : "";
				$users = (preg_match("#^/tfsbox/cpanel/users/?#", $_SERVER['PATH_INFO'])) ? " id=\"active\"" : "";
				$mysql = (preg_match("#^/tfsbox/cpanel/mysql#", $_SERVER['PATH_INFO'])) ? " id=\"active\"" : "";
				$shoutbox = (preg_match("#^/tfsbox/cpanel(?:/shoutbox)?$#", $_SERVER['PATH_INFO'])) ? " id=\"active\"" : "";
				$subs = ($_SERVER['PATH_INFO'] == "/tfsbox/cpanel/subscriptions") ? " id=\"active\"" : "";

				echo "<div id=\"tfsbox_panel_menubar\">\n";

				TFsBOXAbstractView::renderButton("Shout Box", $_SERVER['SCRIPT_NAME']."/tfsbox/cpanel/shoutbox", TFsBOXSession::urlRoot()."/images/icons/shout.png", $shoutbox);

				if (TFsBOX::$Database->databaseMode())
				{
					TFsBOXAbstractView::renderButton("Users", $_SERVER['SCRIPT_NAME'] ."/tfsbox/cpanel/users", TFsBOXSession::urlRoot() ."/images/icons/user.png", $users);
					TFsBOXAbstractView::renderButton("Subscriptions", $_SERVER['SCRIPT_NAME'] ."/tfsbox/cpanel/subscriptions", TFsBOXSession::urlRoot() ."/images/icons/subscribe.png", $subs);
				}

				TFsBOXAbstractView::renderButton("Filters", $_SERVER['SCRIPT_NAME'] ."/tfsbox/cpanel/filters", TFsBOXSession::urlRoot() ."/images/icons/view-filter.png", $filters);

				if (filesize("mysql/db.php") == 0)
					TFsBOXAbstractView::renderButton("Install for MySQL", $_SERVER['SCRIPT_NAME'] ."/tfsbox/cpanel/mysql", TFsBOXSession::urlRoot() ."/images/icons/run-install.png", $mysql);

				echo "</div>\n";
			}

		protected function renderSetupCompletePage()
			{
				echo "<div class=\"tfsbox_container\">";
				echo "<h2>Database Installation Complete</h2>";
				echo "<p>Everything appears to have been installed successfully.</p>";
				echo "<h2>Clean-up Duties</h2>";
				echo "<p>All you have to do is chmod the file <tt>db.php</tt> back to 0644. Nothing else has to be done; keep the file structure in tact and begin using ". TFsBOX::Name ."!</p>";
				echo "</div>";
			}

		protected function renderSetupDatabasePage()
			{
				echo "<form class=\"tfsbox_container\" method=\"post\" action=\"". $_SERVER['SCRIPT_NAME'] ."/tfsbox/cpanel/mysql/install\">\n";
				echo "<table cellspacing=\"5\" cellpadding=\"5\" border=\"0\" style=\"width: 100%;\">\n";
				echo "<colgroup style=\"background-color: #F0F0F0;\"></colgroup>\n";
				echo "<colgroup></colgroup>\n";
				echo "<colgroup style=\"background-color: #F0F0F0;\"></colgroup>\n";
				echo "<tr>\n";
				echo "<th colspan=\"2\" style=\"width: 50%;\">Database Information</th>";
				echo "<th colspan=\"2\" style=\"width: 50%;\">Administrative Account</th>";
				echo "</tr>\n";
				echo "<tr>\n";
				echo "<td><b>Host:</b></td>\n";
				if (!isset($_POST['tfsbox_db_host']))
					$_POST['tfsbox_db_host'] = "localhost";
				echo "<td style=\"width: 30%;\"><input tabindex=\"1\" name=\"tfsbox_db_host\" class=\"tfsbox_textfield\" type=\"text\" value=\"". $_POST['tfsbox_db_host'] ."\" title=\"You most likely do not have to change this value.\"/></td>\n";
				echo "<td><b>Username:</b></td>\n";
				if (!isset($_POST['tfsbox_db_shoutbox_admin_user']))
					$_POST['tfsbox_db_shoutbox_admin_user'] = "admin";
				echo "<td style=\"width: 30%;\"><input tabindex=\"6\" name=\"tfsbox_db_shoutbox_admin_user\" class=\"tfsbox_textfield\" type=\"text\" value=\"". $_POST['tfsbox_db_shoutbox_admin_user'] ."\"/></td>\n";
				echo "</tr>\n";
				echo "<tr>\n";
				echo "<td><b>User:</b></td>\n";
				if (!isset($_POST['tfsbox_db_user']))
					$_POST['tfsbox_db_user'] = "";
				echo "<td><input tabindex=\"2\" name=\"tfsbox_db_user\" class=\"tfsbox_textfield\" type=\"text\" value=\"". $_POST['tfsbox_db_user'] ."\"/></td>\n";
				echo "<td><b>Password:</b></td>\n";
				if (!isset($_POST['tfsbox_db_shoutbox_admin_pass']))
					$_POST['tfsbox_db_shoutbox_admin_pass'] = "";
				echo "<td><input tabindex=\"7\" name=\"tfsbox_db_shoutbox_admin_pass\" class=\"tfsbox_textfield\" type=\"password\" value=\"". $_POST['tfsbox_db_shoutbox_admin_pass'] ."\"/></td>\n";
				echo "</tr>\n";
				echo "<tr>\n";
				echo "<td><b>Password:</b></td>\n";
				if (!isset($_POST['tfsbox_db_pass']))
					$_POST['tfsbox_db_pass'] = "";
				echo "<td><input tabindex=\"3\" name=\"tfsbox_db_pass\" class=\"tfsbox_textfield\" type=\"password\" value=\"". $_POST['tfsbox_db_pass'] ."\"/></td>\n";
				echo "<td><b>E-mail:</b></td>\n";
				if (!isset($_POST['tfsbox_db_shoutbox_admin_email']))
					$_POST['tfsbox_db_shoutbox_admin_email'] = $_SERVER['SERVER_ADMIN'];
				echo "<td><input tabindex=\"8\" name=\"tfsbox_db_shoutbox_admin_email\" class=\"tfsbox_textfield\" type=\"text\" value=\"". $_POST['tfsbox_db_shoutbox_admin_email'] ."\" title=\"Required in case you forget your password.\"/></td>\n";
				echo "</tr>\n";
				echo "<tr>\n";
				echo "<td><b>Database:</b></td>\n";
				if (!isset($_POST['tfsbox_db_name']))
					$_POST['tfsbox_db_name'] = "";
				echo "<td><input tabindex=\"4\" name=\"tfsbox_db_name\" class=\"tfsbox_textfield\" type=\"text\" value=\"". $_POST['tfsbox_db_name'] ."\"/></td>\n";
				echo "</tr>\n";
				echo "<tr>\n";
				echo "<td><b>Prefix:</b></td>\n";
				if (!isset($_POST['tfsbox_db_prefix']))
					$_POST['tfsbox_db_prefix'] = "tfsbox_";
				echo "<td><input tabindex=\"5\" name=\"tfsbox_db_prefix\" class=\"tfsbox_textfield\" type=\"text\" value=\"". $_POST['tfsbox_db_prefix'] ."\"/></td>\n";
				echo "</tr>\n";
				echo "<tr>\n";
				echo "<th colspan=\"4\">\n";
				echo "Additional Information\n";
				echo "</th>\n";
				echo "</tr>\n";
				echo "<tr>\n";
				echo "<td><b>Shoutbox path:</b></td>\n";
				if (!isset($_POST['tfsbox_shoutbox_path']))
					$_POST['tfsbox_shoutbox_path'] = "http://". $_SERVER['SERVER_NAME'] . dirname($_SERVER['SCRIPT_NAME']). "/";
				echo "<td colspan=\"3\"><input tabindex=\"9\" name=\"tfsbox_shoutbox_path\" class=\"tfsbox_textfield\" type=\"text\" value=\"". $_POST['tfsbox_shoutbox_path'] ."\" title=\"The location should be where the shoutbox was installed. This is required for account verification through e-mail.\"/></td>\n";
				echo "</tr>\n";
				echo "<tr>\n";
				echo "<td><b>Verification method:</b></td>\n";
				if (!isset($_POST['tfsbox_verification_method']))
					$_POST['tfsbox_verification_method'] = "email";
				echo "<td colspan=\"3\"><input tabindex=\"10\" name=\"tfsbox_verification_method\" class=\"tfsbox_textfield\" type=\"text\" value=\"". $_POST['tfsbox_verification_method'] ."\" title=\"Possible values: 'email' or 'cpanel'\"/></td>\n";
				echo "</tr>\n";
				echo "<tr>\n";
				echo "<td><b>Maximum log-in attempts:</b></td>\n";
				if (!isset($_POST['tfsbox_max_login_attempts']))
					$_POST['tfsbox_max_login_attempts'] = "5";
				echo "<td colspan=\"3\"><input tabindex=\"11\" name=\"tfsbox_max_login_attempts\" class=\"tfsbox_textfield\" type=\"text\" value=\"". $_POST['tfsbox_max_login_attempts'] ."\"/></td>\n";
				echo "</tr>\n";
				echo "<tr>\n";
				echo "<td><b>Allow guests to shout:</b></td>\n";
				if (!isset($_POST['tfsbox_allow_guests']))
					$_POST['tfsbox_allow_guests'] = "no";
				echo "<td colspan=\"3\"><input tabindex=\"12\" name=\"tfsbox_allow_guests\" class=\"tfsbox_textfield\" type=\"text\" value=\"". $_POST['tfsbox_allow_guests'] ."\" title=\"Possible values: 'yes' or 'no'.\"/></td>\n";
				echo "</tr>\n";
				echo "<tr>\n";
				echo "<td colspan=\"4\" style=\"text-align: right;\">\n";
				echo "<input tabindex=\"14\" type=\"reset\"/>\n";
				echo "<input tabindex=\"13\" type=\"submit\" value=\"Install\"/>\n";
				echo "</td>\n";
				echo "</tr>\n";
				echo "</table>\n";
				echo "</form>\n";
			}

		protected function renderShoutboxPage()
			{
				echo "<form class=\"tfsbox_container\" name=\"tfsbox_shoutbox_settings\" action=\"". $_SERVER['SCRIPT_NAME'] ."/tfsbox/cpanel/shoutbox/settings\" method=\"post\">\n";
				echo "<table cellspacing=\"5\" cellpadding=\"5\" border=\"0\" style=\"width: 100%;\">\n";
				echo "<colgroup style=\"background-color: #F0F0F0;\"></colgroup>\n";
				echo "<colgroup></colgroup>\n";
				echo "<colgroup style=\"background-color: #F0F0F0;\"></colgroup>\n";
				echo "<tr>\n";
				echo "<th colspan=\"4\">Settings</th>\n";
				echo "</tr>\n";
				echo "<tr>\n";
				echo "<td><b>Shouts per page:</b></td>\n";
				echo "<td><input class=\"tfsbox_textfield\" type=\"text\" name=\"tfsbox_shouts_per_page\" value=\"". htmlentities(TFsBOX::$Config->value("shouts_per_page", 10)) ."\"/></td>\n";
				echo "<td><b>Form menu display:</b></td>\n";
				echo "<td>\n";
				echo "<select name=\"tfsbox_form_menu_display\" style=\"width: 100%;\">\n";
				$menu_display = TFsBOX::$Config->value("form_menu_display", "hover");
				echo "<option";
				echo ($menu_display == "hover") ? " selected=\"selected\"" : "";
				echo " value=\"hover\">hover</option>\n";
				echo "<option";
				echo ($menu_display == "click") ? " selected=\"selected\"" : "";
				echo " value=\"click\">click</option>\n";
				echo "</select>\n";
				echo "</td>\n";
				echo "</tr>\n";
				echo "<tr>\n";
				echo "<td><b>Allow images:</b></td>\n";
				echo "<td>\n";
				echo "<select name=\"tfsbox_allow_images\" style=\"width: 100%;\">\n";
				$allow_images = TFsBOX::$Config->value("allow_images", "no");
				echo "<option";
				echo ($allow_images == "yes") ? " selected=\"selected\"" : "";
				echo " value=\"yes\">yes</option>";
				echo "<option";
				echo ($allow_images == "no") ? " selected=\"selected\"" : "";
				echo " value=\"no\">no</option>";
				echo "</select>\n";
				echo "</td>\n";
				echo "<td><b>Name length:</b></td>\n";
				echo "<td><input class=\"tfsbox_textfield\" type=\"text\" name=\"tfsbox_name_length\" title=\"Character length\" value=\"". htmlentities(TFsBOX::$Config->value("name_length", 25)) ."\"/></td>\n";
				echo "</tr>\n";
				echo "<tr>\n";
				echo "<td><b>Site URL:</b></td>\n";
				echo "<td><input class=\"tfsbox_textfield\" type=\"text\" name=\"tfsbox_site_url\" value=\"". htmlentities(TFsBOX::$Config->value("site_url", "http://". $_SERVER['SERVER_NAME'] ."/")) ."\"/></td>\n";
				echo "<td><b>Form Position:</b></td>\n";
				echo "<td>\n";
				echo "<select name=\"tfsbox_form_position\" style=\"width: 100%;\">\n";
				$form_position = TFsBOX::$Config->value("form_position", "bottom");
				echo "<option";
				echo ($form_position == "top") ? " selected=\"selected\"" : "";
				echo " value=\"top\">top</option>\n";
				echo "<option";
				echo ($form_position == "bottom") ? " selected=\"selected\"" : "";
				echo " value=\"bottom\">bottom</option>\n";
				echo "</select>\n";
				echo "</td>\n";
				echo "</tr>\n";
				echo "<tr>\n";
				echo "<td><b>Database Mode:</b></td>\n";
				echo "<td>\n";
				$db_type = TFsBOX::$Config->value("db_type", "flatfile");
				echo "<select name=\"tfsbox_db_type\" style=\"width: 100%;\">\n";
				echo "<option";
				echo ($db_type == "flatfile") ? " selected=\"selected\"" : "";
				echo " value=\"flatfile\">flatfile</option>\n";
				echo "<option";
				echo ($db_type == "mysql") ? " selected=\"selected\"" : "";
				echo " value=\"mysql\">mysql</option>\n";
				echo "</select>\n";
				echo "</td>\n";
				echo "<td><b>Anti-spam timeout:</b></td>\n";
				echo "<td><input class=\"tfsbox_textfield\" type=\"text\" name=\"tfsbox_antispam_timeout\" title=\"Amount in seconds\" value=\"". htmlentities(TFsBOX::$Config->value("antispam_timeout", 5)) ."\"/></td>\n";
				echo "</tr>\n";
				echo "<tr>\n";
				echo "<td><b>Smiley pack:</b></td>\n";
				echo "<td>\n";
				echo "<select name=\"tfsbox_smiley_pack\" style=\"width: 100%;\">\n";
				TFsBOXAbstractView::renderSmileyPackOptions(TFsBOX::$Config->value("smiley_pack", "images/smileys/tfsbox"));
				echo "</select>\n";
				echo "</td>\n";
				echo "</tr>\n";
				echo "<tr>\n";
				echo "<td style=\"text-align: right;\" colspan=\"4\">\n";
				TFsBOXAbstractView::renderButton("Apply", "javascript: document.tfsbox_shoutbox_settings.submit();", TFsBOXSession::urlRoot()."/images/icons/dialog-apply.png", NULL, 3);
				echo "</td>\n";
				echo "</tr>\n";
				echo "</table>\n";
				echo "</form>\n";


				echo "<table class=\"tfsbox_container\" cellspacing=\"5\" cellpadding=\"5\" border=\"0\" style=\"width: 100%;\">\n";
				echo "<tr>\n";
				echo "<th>Shouts</th>\n";
				echo "</tr>\n";
				echo "<tr>\n";
				echo "<td style=\"text-align: right; background-color: #F0F0F0;\">\n";
				TFsBOXAbstractView::renderButton("Clear Reports", $_SERVER['SCRIPT_NAME'] ."/tfsbox/cpanel/reports/clear", TFsBOXSession::urlRoot() ."/images/icons/clear-history.png", NULL, 3);
				TFsBOXAbstractView::renderButton("Clear Shouts", $_SERVER['SCRIPT_NAME'] ."/tfsbox/cpanel/shouts/clear", TFsBOXSession::urlRoot() ."/images/icons/trash-empty.png", NULL, 3);
				echo "</td>\n";
				echo "</tr>\n";
				echo "<tr>\n";
				echo "<td id=\"tfsbox_shouts\">\n";
				$this->renderShouts();
				echo "</td>\n";
				echo "</tr>\n";
				echo "<tr>\n";
				echo "<td style=\"text-align: right; background-color: #F0F0F0;\">\n";
				TFsBOXAbstractView::renderButton("Clear Reports", $_SERVER['SCRIPT_NAME'] ."/tfsbox/cpanel/reports/clear", TFsBOXSession::urlRoot() ."/images/icons/clear-history.png", NULL, 3);
				TFsBOXAbstractView::renderButton("Clear Shouts", $_SERVER['SCRIPT_NAME'] ."/tfsbox/cpanel/shouts/clear", TFsBOXSession::urlRoot() ."/images/icons/trash-empty.png", NULL, 3);
				echo "</td>\n";
				echo "</tr>\n";
				echo "</table>\n";

				echo "<div style=\"clear: both;\"></div>\n";
			}

		protected function renderShouts()
			{
				$arr = TFsBOX::$Database->shouts();
				if (count($arr))
				{
					$arr = array_reverse($arr);

					foreach ($arr as $shout)
						TFsBOXShoutsView::renderShout($shout);
				}

				else echo "<div>There are currently no shouts at this time.</div>\n";
			}

		protected function renderUsersPage()
		{
			echo "<div class=\"tfsbox_container\">\n";
			echo "<h2>Moderators</h2>\n";

			if ($mods = TFsBOX::$Database->moderators())
			{
				echo "<ul>\n";
				foreach ($mods as $mod)
					echo "<li>". $mod['username'] ." <a href=\"". $_SERVER['SCRIPT_NAME'] ."/tfsbox/cpanel/users/demote/". $mod['id'] ."\"><img src=\"". TFsBOXSession::urlRoot() ."/images/icons/remove-operator.png\" alt=\"Demote\"/></a></li>\n";
				echo "</ul>\n";
			}

			else echo "<p>There are no moderators.</p>";

			echo "<h2>Users</h2>\n";

			$ten = 10;
			echo "<h4>$ten Latest Users</h4>\n";
			if ($latest_users = TFsBOX::$Database->latestUsers($ten))
			{
				echo "<ol class=\"users\">\n";
				foreach ($latest_users as $user)
				{
					echo "<li>". $user['username'] ."<br/>\n";
					if ($user['ranking'] == TFsBOXSession::REGULAR)
						echo "<div>". TFsBOXAbstractView::renderButton("Promote ".$user['username'], $_SERVER['SCRIPT_NAME']."/tfsbox/cpanel/users/promote/".$user['id'], TFsBOXSession::urlRoot() ."/images/icons/operator.png") ."</div>\n";
					echo "</li>\n";
				}

				echo "</ol>\n";
			}

			else echo "<p>There are no new users.</p>\n";

			echo "<div style=\"clear: both;\"></div>\n";

			echo "</div>\n";
		}

		protected function renderSubscriptionsPage()
			{
				echo "<div class=\"tfsbox_container\">\n";
				echo "<h2 style=\"margin-bottom: 5px;\">Subscriptions</h2>\n";
				echo "<div class=\"tfsbox_subscriptions\">\n";
				$subs = TFsBOX::$Database->subscriptions(TFsBOX::$Session->userId());
				if ($subs)
				{
					$subs = array_filter(explode("\n", $subs->subscriptions));
					sort($subs);
					if (!empty($subs))
					{
						echo "<ul>\n";
						foreach ($subs as $sub)
						{
							echo "<li onmousedown=\"javascript: get_subscription(this, '$sub', '". $_SERVER['SCRIPT_NAME'] ."/tfsbox/shouts');\">$sub\n";
							echo "<div>\n";
							TFsBOXAbstractView::renderButton("Unsubscribe", $_SERVER['SCRIPT_NAME']."/tfsbox/cpanel/unsubscribe/$sub", TFsBOXSession::urlRoot()."/images/icons/unsubscribe.png", " style=\"float: right; margin: 15px 15px -25px 0;\"");
							echo "<div class=\"shouts\">\n";
							echo "</div>\n";
							echo "</div>\n";
							echo "</li>\n";
						}
						echo "</ul>\n";
					}

					else echo "<div style=\"float: none; border: 0;\">You are not subscribed to anyone.</div>";
				}

				echo "</div>\n";
			}

		function renderUserPanel()
		{
			echo "<div id=\"tfsbox_content\">\n";
			echo "<div class=\"tfsbox_container\">\n";
			echo "<h2 style=\"margin-bottom: 5px;\">Subscriptions</h2>\n";
			echo "<div class=\"tfsbox_subscriptions\">\n";
			$subs = TFsBOX::$Database->subscriptions(TFsBOX::$Session->userId());
			if ($subs)
			{
				$subs = array_filter(explode("\n", $subs->subscriptions));
				sort($subs);
				if (!empty($subs))
				{
					echo "<ul>\n";
					foreach ($subs as $sub)
					{
						echo "<li onmousedown=\"javascript: get_subscription(this, '$sub', '". $_SERVER['SCRIPT_NAME'] ."/tfsbox/shouts');\">$sub\n";
						echo "<div>\n";
						TFsBOXAbstractView::renderButton("Unsubscribe", $_SERVER['SCRIPT_NAME']."/tfsbox/cpanel/unsubscribe/$sub", TFsBOXSession::urlRoot()."/images/icons/unsubscribe.png", " style=\"float: right; margin: 15px 15px -25px 0;\"");
						echo "<div class=\"shouts\">\n";
						echo "</div>\n";
						echo "</div>\n";
						echo "</li>\n";
					}
					echo "</ul>\n";
				}

				else echo "<div style=\"float: none; border: 0;\">You are not subscribed to anyone.</div>";
			}

			else
				echo "<p>You are not subscribed to anyone.</p>\n";

			echo "</div>\n";

			echo "<div style=\"clear: both;\"></div>\n";

			echo "<form method=\"post\" action=\"". $_SERVER['SCRIPT_NAME'] ."/tfsbox/cpanel/update_site\">\n";
			echo "<table cellspacing=\"5\" cellpadding=\"5\" border=\"0\" style=\"width: 100%;\">\n";
			echo "<colgroup style=\"background-color: #F0F0F0;\"></colgroup>\n";
			echo "<colgroup></colgroup>\n";
			echo "<colgroup style=\"background-color: #F0F0F0;\"></colgroup>\n";
			echo "<tr>\n";
			echo "<th colspan=\"2\">Account Information</th>\n";
			echo "</tr>";
			echo "<tr>\n";
			echo "<td><b>Site:</b></td>\n";
			echo "<td><input class=\"tfsbox_textfield\" type=\"text\" name=\"tfsbox_site\" value=\"". htmlentities(TFsBOX::$Session->userSite()) ."\"/></td>\n";
			echo "</tr>\n";
			echo "<tr>\n";
			echo "<td colspan=\"2\" style=\"text-align: right;\">\n";
			echo "<input type=\"submit\" value=\"Apply\"/>\n";
			echo "</td>\n";
			echo "</tr>\n";
			echo "</table>\n";
			echo "</form>\n";

			echo "<form method=\"post\" action=\"\">\n";
			echo "<table cellspacing=\"5\" cellpadding=\"5\" border=\"0\" style=\"width: 100%;\">\n";
			echo "<colgroup style=\"background-color: #F0F0F0;\"></colgroup>\n";
			echo "<colgroup></colgroup>\n";
			echo "<colgroup style=\"background-color: #F0F0F0;\"></colgroup>\n";
			echo "<tr>\n";
			echo "<th colspan=\"4\">Change Password</th>\n";
			echo "</tr>";
			echo "<tr>\n";
			echo "<td><b>Old Password:</b></td>\n";
			echo "<td><input class=\"tfsbox_textfield\" type=\"text\" name=\"tfsbox_old_pass\"/></td>\n";
			echo "<td><b>New Password:</b></td>\n";
			echo "<td><input class=\"tfsbox_textfield\" type=\"text\" name=\"tfsbox_new_pass\"/></td>\n";
			echo "</tr>\n";
			echo "<tr>\n";
			echo "<td colspan=\"4\" style=\"text-align: right;\">\n";
			echo "<input type=\"submit\" value=\"Apply\"/>\n";
			echo "</td>\n";
			echo "</tr>\n";
			echo "</table>\n";
			echo "</form>\n";

			echo "</div>\n";
			echo "</div>\n";
		}
	}

?>
